feat(api): POST /query/timeline and POST /query/compare#9
Merged
Conversation
Expose timeline and compare pipelines via FastAPI with the same window semantics as the CLI (since/from-to, since+baseline, service/env, all_ingestions, ingestion_job_id). JSON responses align with CLI JSON; optional format=text adds a plain-text rendering. Add plain-text timeline formatter for the API. Document endpoints in README and extend unit tests. Closes #6 Made-with: Cursor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements #6 — HTTP API:
POST /query/timelineandPOST /query/compareso API consumers get the same incident workflows as the CLI (raglogs timeline,raglogs compare), without shelling out.Motivation
The README documented FastAPI endpoints for explain, ask, clusters, and ingest, but timeline and compare were CLI-only. Integrations (automation, internal tools, a future web UI) need stable HTTP contracts and JSON aligned with the CLI’s
--format jsonoutput.What’s new
POST /query/timelineraglogs timeline:resolve_window→run_clustering→assemble_evidence→build_timeline.sinceorfrom_time/to_time(same as other query routes).service,env,all_ingestions,ingestion_job_id.format:json(default) ortext.window,ingestion_job_id,all_ingestions,events[].labelfor the timeline column.formatistext, atextfield contains a plain-text rendering (no Rich/ANSI).POST /query/compareraglogs compare:since+baseline(window A ends at request time; B is the same duration offset by baseline), or explicitwindow_a_*/window_b_*ISO datetimes.service,env,all_ingestions,ingestion_job_id,format(json|text).window_a,window_b, cluster diff arrays,new_triggers,dropped_triggers.has_changes(boolean) for quick checks.only_in(a|b).textwhenformatistext.Implementation notes
src/api/routes/compare_windows.pyavoids clashing withsrc.core.compare.compare_windowsinside the handler so unit tests can patchsrc.core.compare.differ.compare_windowsthe same way asexplain_window(avoids a stale module-level binding).src/core/timeline/plain_text.pymirrors CLI layout without pulling Rich into the API layer.Documentation
Testing
tests/unit/test_api.pywith coverage for:events,format=text+text, invalidingestion_job_id→ 400.since/baselineJSON, missing window params → 400,format=text, invalidingestion_job_id→ 400.make test-unit(225 tests) passes.How to verify locally
Checklist
/querywith existing tagsCloses #6
Made with Cursor